package java4_6;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.Arrays;

/**
 *  了解ByteArrayInputStream/ByteArrayOutputStream，写个案例
 */
public class Homework7 {
    public static void main(String[] args) throws IOException {
        ByteArrayOutputStream bout = new ByteArrayOutputStream();
        bout.write("xbl许宝林".getBytes());//字节被放入内部数组

        //close()是空方法，因为是内存操作，所以没有要关闭的资源，不调用也可以
        //但一般养成习惯写closeb()方法
        bout.close();

        byte[] a  = bout.toByteArray();
        System.out.println(Arrays.toString(a));

        ByteArrayInputStream binput = new ByteArrayInputStream(a);
        int c = 0 ;
        while ((c = binput.read())!= -1 ){
            System.out.print((char)c+" ");
        }
        binput.close();
    }
}
